package com.JVM;

import java.util.concurrent.TimeUnit;

public class App1 {


    public static void main(String[] args) {
        Object lock1 = new Object();
        Object lock2 = new Object();
        LockT l1 = new LockT(lock1, lock2);
        LockT l2 = new LockT(lock2, lock1);
        Thread t1 = new Thread(l1);
        Thread t2 = new Thread(l2);
        t1.start();
        t2.start();
    }


    static class LockT implements Runnable {
        private Object lock1;
        private Object lock2;

        public LockT(Object lock1, Object lock2) {
            this.lock1 = lock1;
            this.lock2 = lock2;
        }

        public void run() {
            synchronized (lock1) {
                try {
                    TimeUnit.SECONDS.sleep(3);
                    synchronized (lock2) {
                        System.out.println(Thread.currentThread().getName() + "....");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
